package com.example.makerspace;

import java.io.File;

import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.SourceDataLine;
public class MyAudioPlayer {

    /**
     * @param args
     */

    public static void main(String[] args) {
        MyAudioPlayer lx = new MyAudioPlayer();
        lx.run();
        Thread sy=new Thread();
        sy.start();

    }


    public void run() {

        //File wjl = new File(wjm);
        AudioInputStream ypsrl = null;
        try {
            ypsrl = AudioSystem.getAudioInputStream(new File("C:\\Users\\Lenovo\\Desktop\\cyber-co-creation-backend\\src\\main\\resources\\templates\\call.mp3"));
        } catch (Exception e) {
            System.out.println("文件为空");
        }

        AudioFormat format = ypsrl.getFormat();
        SourceDataLine aqsj = null;
        DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);

        try {
            aqsj = (SourceDataLine) AudioSystem.getLine(info);// 格式化包装
            aqsj.open(format);
        } catch (Exception e) {
        }
        aqsj.start();

        int zjtj = 0;
        byte[] hczj = new byte[1024];// 小需要缓冲
        try {
            while (zjtj != -1) {
                zjtj = ypsrl.read(hczj, 0, hczj.length);
                if (zjtj >= 0)
                    aqsj.write(hczj, 0, zjtj);
            }
        } catch (Exception e) {
        } finally {
            aqsj.drain();// 将残留部分处理干净
            aqsj.close();
        }
    }




}
